#include <string>
#include <iostream>
#include "LuaApi.h"

lua_State *g_main_state = nullptr;

void luaapi_init()
{
    g_main_state = luaL_newstate();
    luaL_openlibs(g_main_state);

    luabridge::getGlobalNamespace(g_main_state)
        .beginNamespace("__application__")
        .endNamespace();


    std::string script_text = "print(11)";
    auto L = g_main_state;
    int result = luaL_loadstring(L, script_text.c_str()) || lua_pcall(L, 0, 0, 0);
    if (result != 0)
    {
        std::cerr << "LuaScriptApplication::DoString ERROR: " << lua_tostring(L, -1);
        lua_pop(L, 1);
    }
}
